$(function () {
    var userId = $.url().param("userId");
    var userType = $.url().param("userType");

    if (userId == "") {
        userId = sessionStorage.getItem("userId");
        userType = sessionStorage.getItem("userType");
    }
    sessionStorage.setItem("userId", userId);
    sessionStorage.setItem("userType", userType);
    $(".qna-experience").click(function(){
        window._hmt && window._hmt.push(['_trackEvent', '意外险活动', '通关宝典', "通关宝典"]);
        window.location.href = "https://act.cx580.com/page/PiccPromote/index.html";
    });
    $(".beginning-btn").click(function(){
        window._hmt && window._hmt.push(['_trackEvent', '意外险活动', '开始挑战', "通关宝典"]);
        if(userId == "" || userId == undefined) {
            var logginUrl = "https://auth.cx580.com/Auth.aspx?authType=app&userType=app&clientId=CheWu&redirect_uri=";
            var qnaUrl = "https://act.cx580.com/page/Piccqa/qna.html";
            window.location.href = logginUrl + qnaUrl;
        }else {
            $.ajax({
                url: "../../Handler/UserCouponHandler.ashx?Action=getCoupon",
                type: "POST",
                data: {
                    userId: userId,
                    userType: userType
                    //errorCount: 0
                },
                success: function (res) {
                    var jsonData = JSON.parse(res);
                    if (jsonData.status) {
                        var couponId = jsonData.data;
                        if(couponId == "") {
                            window.location.href = logginUrl + qnaUrl;
                        }else if (couponId == "100221") {
                            window.location.replace("qna-fail.html?coupon=" + jsonData.data);
                        }
                        else {
                            window.location.replace("qna-success.html?coupon=" + jsonData.data);
                        }
                    }
                }
            });

        }
    });
});

